
//
//  GuidViewController.m
//  helloword
//
//  Created by chen on 17/3/6.
//  Copyright © 2017年 chen. All rights reserved.
//

#import "GuidViewController.h"
#import "ViewController.h"
#import "RefreshViewController.h"

@interface GuidViewController ()<UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
@property (strong,nonatomic) UIImageView *imageView1;
@property (strong,nonatomic) UIImageView *imageView2;
@property (strong,nonatomic) UIImageView *imageView3;
@property (strong, nonatomic) IBOutlet UIButton *clickButton;

@end

@implementation GuidViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUIScreen];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)initUIScreen{
    self.scrollView.delegate = self;
    CGFloat scrollWidth = self.view.frame.size.width;
    CGFloat scrollHeight = self.view.frame.size.height;
    self.scrollView.frame = self.view.frame;
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 3, self.scrollView.frame.size.height);
    self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(scrollWidth * 0, 0.0f, scrollWidth, scrollHeight)];
    self.imageView1.image = [UIImage imageNamed:@"famliy1"];
    [self.scrollView addSubview:_imageView1];
    self.imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(scrollWidth * 1, 0.0f, scrollWidth, scrollHeight)];
    self.imageView2.image = [UIImage imageNamed:@"famliy2"];
    [self.scrollView addSubview:_imageView2];
    self.imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(scrollWidth * 2, 0.0f, scrollWidth, scrollHeight)];
    self.imageView3.image = [UIImage imageNamed:@"famliy3"];
    [self.scrollView addSubview:_imageView3];
    self.clickButton.layer.cornerRadius = 10.0;
    self.clickButton.enabled = false;
    self.clickButton.alpha = 0.0;
    [_clickButton addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void) onClick{
    NSLog(@"点击了onClick时间");
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//    [self presentViewController:navigationVC animated:TRUE completion:nil];
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.rootViewController = tabBarController;
    //设置几个tabBar
    ViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
    UINavigationController *navigationFirst = [[UINavigationController alloc] initWithRootViewController:viewController];
//    UITableViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
    RefreshViewController *tableViewController = [[RefreshViewController alloc]init];
    UINavigationController *navigationSecond = [[UINavigationController alloc] initWithRootViewController:tableViewController];
    self.tabBarController.viewControllers = @[navigationFirst,navigationSecond];
    
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint offsize = scrollView.contentOffset;
    self.pageControl.currentPage = offsize.x/self.view.frame.size.width;
    if (self.pageControl.currentPage == 2) {
        [UIView animateWithDuration:0.5 animations:^{
            self.clickButton.enabled = true;
            self.clickButton.alpha = 1.0;
        }];
    }else{
        [UIView animateWithDuration:0.5 animations:^{
            self.clickButton.enabled = false;
            self.clickButton.alpha = 0.0;
        }];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
